﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Kaidou.Persister;
using Kaidou.Model;
using Kaidou.Util;
using Kaidou.Bll;



public partial class seal_seal_order_paper : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginModel loginModel = (LoginModel)Session["loginModel"];
        if (loginModel == null)
        {
            Response.Redirect("../login.aspx");
        }

        if (loginModel.isKumiaiin())
        {
            Response.Redirect("../menu.aspx");
        }

        if (loginModel.isKumiaiin() && sessioncontrol.control())
        {
            Response.Redirect("../control.aspx");
        }

        try
        {

            Order order = new Order();
            //TRN_Juchu_HPersister parH = new TRN_Juchu_HPersister();
            //TRN_Juchu_DPersister parD = new TRN_Juchu_DPersister();
           // string juchu_no = Request.QueryString["juchu_no"].ToString();
            //TrnJuchuh h = order.getJuchu_H();
            //TrnJuchud[] d = order.getJuchu_D();

            TRN_Juchu_HPersister parH = new TRN_Juchu_HPersister();
            TRN_Juchu_DPersister parD = new TRN_Juchu_DPersister();
            string juchu_no = Request.QueryString["juchu_no"].ToString();
            TrnJuchuh h = parH.getDetail(juchu_no);
            TrnJuchud[] d = parD.getDetail(juchu_no);
            order.setJuchu_H(h);
            order.setJuchu_D(d);
           
            MST_UnionPersister dao1 = new MST_UnionPersister();
            MST_Union_BranchPersister dao2 = new MST_Union_BranchPersister();
            MstUnion union = dao1.getDetail(h.UnionCode);
            mst_union_branch branch = dao2.getDetail(h.UnionCode, h.BranchCode);
            /*
            mst_union_branch hachu_union = null;
            if (h.HachuUnionCode != null)
            {
                hachu_union = dao2.getDetail(h.HachuUnionCode, h.HachuBranchCode);
            }
             **/
            string hachu_union_name = "";
            if (h.HachuUnionCode != null)
            {
                if (h.HachuBranchCode > 0)
                {
                    mst_union_branch m1 = dao2.getDetail(h.HachuUnionCode, h.HachuBranchCode);
                    hachu_union_name = m1 != null ? m1.officename : "";
                }
                else
                {
                    MstUnion m2 = dao1.getDetail(h.HachuUnionCode);
                    hachu_union_name = m2 != null ? m2.OfficeName : "";
                }
            }


            if (TrnJuchuh.JUCHU_CLSS_INTERNET.Equals(h.JuchuClss))
            {
                htitle.Text = "インターネット";
            }
            else if (TrnJuchuh.JUCHU_CLSS_FAX.Equals(h.JuchuClss))
            {
                htitle.Text = "FAX/OCR";
            }

            JUCHU_DATE.Text = ((DateTime)h.JuchuDate).ToString("yyyy年MM月dd日");
            if (h.FaxRcvDate != null && !h.FaxRcvDate.ToString().Equals(""))
            {
                faxrcvdate.Text = ((DateTime)h.FaxRcvDate).ToString("yyyy年MM月dd日 hh:mm");
            }
            MST_UNION_CODE.Text = h.UnionCode;
            ParentOfficeName.Text = union == null ? "" : union.OfficeName;
            MST_BRANCH_CODE.Text = h.BranchCode == 0 ? "000" : h.BranchCode.ToString();
            Branch_office_name.Text = branch == null ? "本店" : branch.officename;
            TRN_JUCHU_TANTO_NAME.Text = h.JuchuTantoName;

            if (h.HopeDate != null)
            {
                DateTime dt = (DateTime)h.HopeDate;
                TRN_HOPE_DATE.Text = dt.ToString("yyyy年MM月dd日");

            }
            else
            {
                TRN_HOPE_DATE.Text = "指定なし";
            }

            if (TrnJuchuh.HOPE_TIME_CLSS_NONE.Equals(h.HopeTimeClss))
            {
                TRN_HOPE_TIME_CLSS.Text = "指定なし";
            }

            if (TrnJuchuh.HOPE_TIME_CLSS_MORNING.Equals(h.HopeTimeClss))
            {
                TRN_HOPE_TIME_CLSS.Text = "午前";
            }

            if (TrnJuchuh.HOPE_TIME_CLSS_AFTERNOON.Equals(h.HopeTimeClss))
            {
                TRN_HOPE_TIME_CLSS.Text = "午後";
            }
            string area = Resources.Resource.area;
                string[] areaArray = area.Split(',');

            if (branch != null)
            {
                
                addressmsg.Text = "〒" + branch.officezipno.Substring(0, 3) + "-" + branch.officezipno.Substring(3, 4) + "<br/>" + areaArray[branch.officeprefcode-1] + " " + branch.officecity + " " + branch.officeaddress + "<br/>" +
                    "TEL：" + branch.officetel + " FAX：" + branch.officefax;

            }else if (h.BranchCode == 0 && union != null)
            {
                addressmsg.Text = "〒" + union.OfficeZipNo.Substring(0, 3) + "-" + union.OfficeZipNo.Substring(3, 4) + "<br/>" + areaArray[union.OfficePrefCode-1] + " " + union.OfficeCity + " " + union.OfficeAddress + "<br/>" +
                    "TEL：" + union.OfficeTel + " FAX：" + union.OfficeFax;
            }
            else
            {
                addressmsg.Text = "組合員が見つかりません。";
            }

            TRN_SEAL_QTY1.Text = d[0] == null ? "" : d[0].SealQty.ToString();
            seal_str_end_no_1.Text = d[0] == null ? "～" : d[0].SealStrNo + "～" + d[0].SealEndNo;

            Kaidou.Persister.MST_TraderPersister traderDao = new Kaidou.Persister.MST_TraderPersister();
            MstTrader trader = null;

            if (d[1] != null)
            {
                trader = traderDao.getDetail(d[1].TraderRegNo);
                TRADER_REG_NO2.Text = trader != null ? trader.TraderRegNo.Substring(0, 2) + " - " + trader.TraderRegNo.Substring(2, 5) : "";
                TRADER_REG_NO_LABEL2.Text = trader != null ? trader.TraderName : "";
                TRN_SEAL_QTY2.Text = d[1] != null ? d[1].SealQty.ToString() : "";
                seal_str_end_no_2.Text = d[1] == null ? "～" : d[1].SealStrNo + "～" + d[1].SealEndNo;
            }
            else
            {
                seal_str_end_no_2.Text = "～";
            }

            if (d[2] != null)
            {
                trader = traderDao.getDetail(d[2].TraderRegNo);
                TRADER_REG_NO3.Text = trader != null ? trader.TraderRegNo.Substring(0, 2) + " - " + trader.TraderRegNo.Substring(2, 5) : "";
                TRADER_REG_NO_LABEL3.Text = trader != null ? trader.TraderName : "";
                TRN_SEAL_QTY3.Text = d[2] != null ? d[2].SealQty.ToString() : "";
                seal_str_end_no_3.Text = d[2] == null ? "～" : d[2].SealStrNo + "～" + d[2].SealEndNo;
            }
            else
            {
                seal_str_end_no_3.Text = "～";
            }

            if (d[3] != null)
            {
                trader = traderDao.getDetail(d[3].TraderRegNo);
                TRADER_REG_NO4.Text = trader != null ? trader.TraderRegNo.Substring(0, 2) + " - " + trader.TraderRegNo.Substring(2, 5) : "";
                TRADER_REG_NO_LABEL4.Text = trader != null ? trader.TraderName : "";
                TRN_SEAL_QTY4.Text = d[3] != null ? d[3].SealQty.ToString() : "";
                seal_str_end_no_4.Text = d[3] == null ? "～" : d[3].SealStrNo + "～" + d[3].SealEndNo;
            }
            else
            {
                seal_str_end_no_4.Text = "～";
            }

            if (d[4] != null)
            {
                trader = traderDao.getDetail(d[4].TraderRegNo);
                TRADER_REG_NO5.Text = trader != null ? trader.TraderRegNo.Substring(0, 2) + " - " + trader.TraderRegNo.Substring(2, 5) : "";
                TRADER_REG_NO_LABEL5.Text = trader != null ? trader.TraderName : "";
                TRN_SEAL_QTY5.Text = d[4] != null ? d[4].SealQty.ToString() : "";
                seal_str_end_no_5.Text = d[4] == null ? "～" : d[4].SealStrNo + "～" + d[4].SealEndNo;
            }
            else
            {
                seal_str_end_no_5.Text = "～";
            }

            sum.Text = h.TotalSealQty.ToString();

           // ocr_order_qty.Text = h.OcrOrderQty.ToString();

            hachu_date.Text = h.HachuDate == null ? "" : ((DateTime)h.HachuDate).ToString("yyyy年MM月dd日");
            hachu_union_office_name.Text = hachu_union_name;
            deliv_date.Text = h.DelivDate == null ? "" : ((DateTime)h.DelivDate).ToString("yyyy年MM月dd日");
            deliv_tanto_name.Text = h.DelivTantoName == null ? "" : h.DelivTantoName;
            deliv_comp_name.Text = h.DelivCompName == null ? "" : h.DelivCompName;
            deliv_no.Text = h.DelivNo == null ? "" : h.DelivNo;

            //表示モード。PAPERVIEWがOFFだったら戻るボタンを表示する。
            //bool view = "off".Equals(Request.QueryString["PAPERVIEW"].ToString()));
            //viewflag.Visible = false;
	

        }
        catch (Exception ex)
        {

            LogManager.error("seal_seal_order_paper " + ex.Message + ex.StackTrace+ex.Source);
        }
    }
}
